package com.yiqi.lottery.feature.mine.view;

import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.text.Html;
import android.view.Gravity;
import android.widget.LinearLayout;
import android.widget.TextView;
import butterknife.BindView;
import butterknife.ButterKnife;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.suozhang.framework.entity.bo.PageData;
import com.suozhang.framework.framework.AM;
import com.suozhang.framework.framework.BaseActivity;
import com.yiqi.lottery.R;
import com.yiqi.lottery.entity.bo.CharsBo;
import com.yiqi.lottery.feature.mine.contract.NumberContract;
import com.yiqi.lottery.feature.mine.dependencies.number.DaggerNumberComponent;
import com.yiqi.lottery.feature.mine.dependencies.number.NumberPresenterModule;

import javax.inject.Inject;
import java.util.List;

public class NUmberDetailActivity extends BaseActivity implements NumberContract.View {

    @BindView(R.id.toolbar)
    Toolbar mToolbar;
    @BindView(R.id.tv_user_number_type_name)
    TextView mTvUserNumberTypeName;
    @BindView(R.id.tv_user_number_state)
    TextView mTvUserNumberState;
    @BindView(R.id.tv_user_number_no)
    TextView mTvUserNumberNo;
    @BindView(R.id.tv_user_number_amount)
    TextView mTvUserNumberAmount;
    @BindView(R.id.tv_user_number_prize)
    TextView mTvUserNumberPrize;
    @BindView(R.id.view_user_number_list)
    LinearLayout mViewUserNumberList;
    @BindView(R.id.tv_user_number_qi)
    TextView mTvUserNumberQi;
    @BindView(R.id.view_charsing_list)
    LinearLayout mViewCharsingList;
    @BindView(R.id.tv_user_number_result)
    TextView mTvUserNumberResult;
    private Integer mId;
    @Inject
    NumberContract.Presenter mPresenter;

    @Override
    protected int attachLayoutRes() {
        return R.layout.activity_number_detail;
    }

    @Override
    protected void initInjector() {
        DaggerNumberComponent.builder().numberPresenterModule(new NumberPresenterModule(this)).build().inject(this);
    }


    @Override
    protected void initView() {
        initToolBar(mToolbar, "追号详情", true, true);
    }

    @Override
    protected void initData() {
        mId = this.getIntent().getIntExtra("id", 0);
        mPresenter.getMyCharsDetail(mId);
    }


    @Override
    public void showMyBanlanceSuccess(PageData<CharsBo> msg) {

    }

    @Override
    public void showMyBanlanceError(String msg) {
        showMsg("Error");
    }

    @Override
    public void showMyBanlanceMoreSuccess(PageData<CharsBo> msg) {

    }

    @Override
    public void showMyBanlanceMoreError(String msg) {

    }

    @Override
    public void showMyBanlanceEmpty() {

    }

    @Override
    public void showNumberDetailSuccess(CharsBo item) {


        if (item == null) return;
        try {
            String stauts = item.getOrder_status() == 1 ? "进行中" : item.getOrder_status() == 2 ? "已完成" : item.getOrder_status() == 3 ? "已取消" : "";
            mTvUserNumberTypeName.setText("大乐透");
            mTvUserNumberState.setText(Html.fromHtml("状态：<font color=\"#333333\">" + stauts + "</font>"));
            mTvUserNumberNo.setText(Html.fromHtml("编号：<font color=\"#333333\">" + item.getOrder_sn() + "</font>"));
            mTvUserNumberAmount.setText(Html.fromHtml("总投金额：<font color=\"#333333\">\t\t\t" + item.getOrder_amount() + "元</font>"));
            mTvUserNumberPrize.setText(Html.fromHtml("中奖金额：<font color=\"#333333\">\t\t\t" + "1000元" + "</font>"));
            String[] data = item.getBet_code().split(";");
            for (int i = 0; i < data.length; i++) {
                TextView textView = new TextView(this);
                textView.setTextSize(13);
                textView.setGravity(Gravity.LEFT);
                textView.setPadding(1, 8, 0, 0);//l
                textView.setText(Html.fromHtml("<font color=\"#333333\">" + data[i].replaceAll("\\|", "\t\t").replaceAll(",", "\t") + "</font>"));
                mViewUserNumberList.addView(textView);
            }
            mTvUserNumberQi.setText("已追" + item.getHas_charsing() + "期/共" + item.getCharsing_num() + "期");
            mTvUserNumberResult.setText(Html.fromHtml("开奖结果：<font color=\"#333333\">\t\t\t" + "2 4 5 6 7 2 8" + "</font>"));
            if (item.getCharsing() != null)
                for (int i = 0; i < item.getCharsing().size(); i++) {
                    CharsBo.CharsingBean charsingBean = item.getCharsing().get(i);
                    TextView mTextView = new TextView(this);
                    mTextView.setTextSize(13);
                    mTextView.setGravity(Gravity.LEFT);
                    mTextView.setPadding(1, 5, 0, 0);//left, top, right, bottom
                    if (charsingBean != null) {
                        String staut = charsingBean.getStatus() == 1 ? "进行中" : charsingBean.getStatus() == 2 ? "已完成" : charsingBean.getStatus() == 3 ? "已取消" : "";

                        mTextView.setText(Html.fromHtml("<font color=\"#ff6b6b6b\">第" + charsingBean.getIssue_id() + "期</font>\t\t\t\t"
                                + "<font color=\"#333333\">投注" + charsingBean.getAmount() + "元</font>\t\t\t\t\t\t\t\t\t\t\t"
                                + "<font color=\"#333333\">" + staut + "</font>"
                        ));
                    }
                    mViewCharsingList.addView(mTextView);
                }

        } catch (Exception e) {

        }
    }


}
